<?php
/**
 * User: hjd-yao
 * Date: 2018/11/4
 * Time: 15:59
 */

namespace App\Http\Controllers\Auth;


use App\Helpers\SelfEncrypt;
use App\Helpers\SelfResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\LoginRequest;
use App\Models\ManageAdminModel;
use Carbon\Carbon;

class LoginController extends Controller
{
    public function showLoginForm()
    {
        return view('auth::default.index');
    }

    public function login(LoginRequest $request)
    {

        $admin_name = $request->post('username');
        $login_pwd = $request->post('pass');
        $adminModel = new ManageAdminModel();
        if(!$adminModel->login($admin_name,$login_pwd)){
            return SelfResponse::error($adminModel->getErrorMsg());
        }
        $jump_url = $adminModel->getJumpUrl();
        return SelfResponse::success('登录成功',$jump_url);
    }

    public function logout()
    {
        ManageAdminModel::init()->logout();
        return redirect()->route('b_Login_showLoginForm');
    }
}